from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-07 14:06:02.334369
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 07, Feb, 2021
Time: 14:06:06
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.9546
Nobs: 195.000 HQIC: -46.8536
Log likelihood: 2227.62 FPE: 2.43488e-21
AIC: -47.4652 Det(Omega_mle): 1.55240e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.462208 0.141453 3.268 0.001
L1.Burgenland 0.099170 0.073348 1.352 0.176
L1.Kärnten -0.220697 0.060781 -3.631 0.000
L1.Niederösterreich 0.134064 0.169757 0.790 0.430
L1.Oberösterreich 0.235189 0.148386 1.585 0.113
L1.Salzburg 0.195805 0.078650 2.490 0.013
L1.Steiermark 0.091237 0.105553 0.864 0.387
L1.Tirol 0.153404 0.071165 2.156 0.031
L1.Vorarlberg -0.006302 0.064986 -0.097 0.923
L1.Wien -0.129667 0.142668 -0.909 0.363
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.500824 0.174198 2.875 0.004
L1.Burgenland 0.016082 0.090328 0.178 0.859
L1.Kärnten 0.365029 0.074852 4.877 0.000
L1.Niederösterreich 0.119338 0.209054 0.571 0.568
L1.Oberösterreich -0.142382 0.182736 -0.779 0.436
L1.Salzburg 0.194282 0.096857 2.006 0.045
L1.Steiermark 0.229707 0.129988 1.767 0.077
L1.Tirol 0.140836 0.087639 1.607 0.108
L1.Vorarlberg 0.176862 0.080030 2.210 0.027
L1.Wien -0.588532 0.175694 -3.350 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.304513 0.062853 4.845 0.000
L1.Burgenland 0.107932 0.032592 3.312 0.001
L1.Kärnten -0.020940 0.027008 -0.775 0.438
L1.Niederösterreich 0.071701 0.075430 0.951 0.342
L1.Oberösterreich 0.281430 0.065934 4.268 0.000
L1.Salzburg 0.004753 0.034947 0.136 0.892
L1.Steiermark -0.018359 0.046902 -0.391 0.695
L1.Tirol 0.090736 0.031621 2.869 0.004
L1.Vorarlberg 0.110549 0.028876 3.828 0.000
L1.Wien 0.073082 0.063393 1.153 0.249
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.223064 0.071552 3.117 0.002
L1.Burgenland -0.013371 0.037102 -0.360 0.719
L1.Kärnten 0.023760 0.030746 0.773 0.440
L1.Niederösterreich 0.035249 0.085870 0.410 0.681
L1.Oberösterreich 0.382781 0.075060 5.100 0.000
L1.Salzburg 0.094668 0.039784 2.380 0.017
L1.Steiermark 0.185796 0.053393 3.480 0.001
L1.Tirol 0.040245 0.035998 1.118 0.264
L1.Vorarlberg 0.091178 0.032873 2.774 0.006
L1.Wien -0.065653 0.072167 -0.910 0.363
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.526914 0.142813 3.690 0.000
L1.Burgenland 0.063388 0.074053 0.856 0.392
L1.Kärnten 0.014281 0.061366 0.233 0.816
L1.Niederösterreich -0.024724 0.171389 -0.144 0.885
L1.Oberösterreich 0.152117 0.149813 1.015 0.310
L1.Salzburg 0.054500 0.079406 0.686 0.492
L1.Steiermark 0.123870 0.106568 1.162 0.245
L1.Tirol 0.207243 0.071849 2.884 0.004
L1.Vorarlberg 0.028444 0.065611 0.434 0.665
L1.Wien -0.135183 0.144040 -0.939 0.348
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161769 0.100881 1.604 0.109
L1.Burgenland -0.021996 0.052311 -0.420 0.674
L1.Kärnten -0.012420 0.043348 -0.287 0.774
L1.Niederösterreich 0.117011 0.121067 0.966 0.334
L1.Oberösterreich 0.389494 0.105826 3.681 0.000
L1.Salzburg -0.018525 0.056092 -0.330 0.741
L1.Steiermark -0.022818 0.075279 -0.303 0.762
L1.Tirol 0.190136 0.050754 3.746 0.000
L1.Vorarlberg 0.036902 0.046347 0.796 0.426
L1.Wien 0.187719 0.101748 1.845 0.065
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.235866 0.128699 1.833 0.067
L1.Burgenland 0.067831 0.066735 1.016 0.309
L1.Kärnten -0.041532 0.055301 -0.751 0.453
L1.Niederösterreich -0.025875 0.154451 -0.168 0.867
L1.Oberösterreich -0.100273 0.135007 -0.743 0.458
L1.Salzburg 0.032073 0.071559 0.448 0.654
L1.Steiermark 0.393224 0.096036 4.095 0.000
L1.Tirol 0.492437 0.064748 7.605 0.000
L1.Vorarlberg 0.165063 0.059127 2.792 0.005
L1.Wien -0.216805 0.129805 -1.670 0.095
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.076585 0.155994 0.491 0.623
L1.Burgenland 0.032329 0.080888 0.400 0.689
L1.Kärnten -0.089174 0.067030 -1.330 0.183
L1.Niederösterreich 0.241749 0.187207 1.291 0.197
L1.Oberösterreich -0.006587 0.163640 -0.040 0.968
L1.Salzburg 0.233024 0.086735 2.687 0.007
L1.Steiermark 0.134151 0.116404 1.152 0.249
L1.Tirol 0.072354 0.078481 0.922 0.357
L1.Vorarlberg 0.042386 0.071667 0.591 0.554
L1.Wien 0.269705 0.157334 1.714 0.086
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.595930 0.082376 7.234 0.000
L1.Burgenland -0.025884 0.042715 -0.606 0.545
L1.Kärnten -0.003431 0.035396 -0.097 0.923
L1.Niederösterreich -0.037179 0.098859 -0.376 0.707
L1.Oberösterreich 0.290012 0.086413 3.356 0.001
L1.Salzburg 0.016345 0.045802 0.357 0.721
L1.Steiermark 0.012534 0.061470 0.204 0.838
L1.Tirol 0.079077 0.041443 1.908 0.056
L1.Vorarlberg 0.137543 0.037845 3.634 0.000
L1.Wien -0.059853 0.083084 -0.720 0.471
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.141813 0.030969 0.207140 0.255956 0.068053 0.089270 -0.060012 0.174680
Kärnten 0.141813 1.000000 0.016229 0.191494 0.161669 -0.113806 0.166071 0.022368 0.312430
Niederösterreich 0.030969 0.016229 1.000000 0.313160 0.086452 0.217055 0.140666 0.053183 0.369051
Oberösterreich 0.207140 0.191494 0.313160 1.000000 0.302603 0.295851 0.114141 0.080433 0.136166
Salzburg 0.255956 0.161669 0.086452 0.302603 1.000000 0.155911 0.059985 0.088082 -0.018555
Steiermark 0.068053 -0.113806 0.217055 0.295851 0.155911 1.000000 0.111354 0.093281 -0.090932
Tirol 0.089270 0.166071 0.140666 0.114141 0.059985 0.111354 1.000000 0.161299 0.154475
Vorarlberg -0.060012 0.022368 0.053183 0.080433 0.088082 0.093281 0.161299 1.000000 0.071146
Wien 0.174680 0.312430 0.369051 0.136166 -0.018555 -0.090932 0.154475 0.071146 1.000000